const chalk = require('chalk')
const asTable = require ('as-table').configure({
    title: x => chalk.whiteBright(x),
    delimiter: chalk.cyan(' | '),
    dash: '~',
})

let exportVar = (function() {
    let stat = []
    return {
        clear() {
            stat = []
        },
        append(object) {
            object.reponame = object.reponame.replace(/.*\//, '').replace(/\.git$/, '')
            switch (object.flag) {
                case ERROR.OK:
                    object.flag = ' ' + chalk.green('√')
                    break
                case ERROR.NO_ENTRY:
                    object.flag = ' ' + chalk.gray('-')
                    break
                case ERROR.CONFLICT:
                    object.flag = ' ' + chalk.yellow('?')
                    break
                case ERROR.FAILURE:
                    object.flag = ' ' + chalk.red('X')
                    break
                default:
                    object.flag = ' ' + `?${object.flag}?`
                    break
            }

            stat.push(object)
        },
        print() {
            console.log(asTable(stat))
        },
    }
})()

module.exports = exportVar
